<template>
	<view class="order">
		<uni-nav-bar left-icon="arrowleft" right-icon="search" title="盘点列表" @clickLeft="back" @clickRight="find" :fixed="true" class="top" status-bar></uni-nav-bar>
		<view v-if="dataList.length != 0">
			<view class="list" v-if="dataList.length != 0">
				<view class="li" v-for="(item, index) in dataList" :key="index" @click="details(item.id)">
					<view class="order">盘点单号：158965228335653</view>
					<view class="shop">
						<view class="msg">
							<view class="black">春装换季盘点</view>
							<view class="time">2019-06-24 16:24:56</view>
						</view>
					</view>
					<view class="genre">
						<view class="msg">
							<view class="audit audit1" @click="go_finish(item.id)">完成盘点</view>
							<view class="audit" @click="go_detalis(item.id)">查看详情</view>
						</view>
					</view>
				</view>
			</view>
			<view class="pagination" v-if="dataList.length != 0">
				<view class="left" :class="{ forbid: paging.page == 1 }" @click="prev">
					<uni-icons type="arrowleft" size="20" color="#fff" class="icons" />
					上一页
				</view>
				<view class="center">{{ paging.page }}/{{ paging.total }}</view>
				<view class="right" :class="{ forbid: paging.page == paging.total }" @click="next">
					下一页
					<uni-icons type="arrowright" size="20" color="#fff" class="icons" />
				</view>
			</view>
			<view class="go-top" v-show="is_go_top" @click="backTop"><image src="/static/img/go_top.png" /></view>
		</view>
		
		<view v-else class="notavailable">
			<image src="../../../static/img/notavailable.png" mode="widthFix"></image>
			<view class="nottext">暂时没有数据</view>
		</view>
	</view>
</template>

<script>
import { uniNavBar, uniIcons } from '@dcloudio/uni-ui';
import check from '../../../servers/entrepot/check.js';
export default {
	components: { uniNavBar, uniIcons },
	data() {
		return {
			active: 1,
			dataList: [],
			obj: '',
			paging: {
				page: 1,
				total: 100
			},
			is_go_top: false
		};
	},
	onPageScroll: function(e) {
		//nvue暂不支持滚动监听，可用bindingx代替
		if (e.scrollTop > 200) {
			this.is_go_top = true;
		} else {
			this.is_go_top = false;
		}
	},
	mounted() {
		this.obj = this.active + '';
		this.getData(this.obj);
	},
	methods: {
		getData(e) {
			var obj = {
				currentPage: this.paging.page,
				pageSize: 10
			};
			this.dataList = [];
			check
				.initData(e, obj)
				.then(res => {
					this.dataList = res.data.records.map(v => {
						v.image = this.imgCDNUrl + v.productImg;
						var sku = [];
						if (v.spec) {
							sku = v.spec.split(',');
						}
						v.sku = sku;
						return v;
					});
				})
				.catch(err => {
					console.log(new Error('请检查网络后重试'));
				});
		},
		back() {
			uni.navigateBack({
				delta: 1
			});
		},
		find(e) {},
		next() {
			if (this.paging.page < this.paging.total) {
				this.paging.page += 1;
				this.getData(this.active + '');
			}
		},
		prev() {
			if (this.paging.page > 1) {
				this.paging.page -= 1;
				this.getData(this.active + '');
			}
		},
		// 计算距离顶部的高度，均分10等分，
		backTop() {
			uni.pageScrollTo({
				scrollTop: 0,
				duration: 200
			});
		},
		go_detalis(e) {
			uni.setStorage({
			    key: 'entrepotdetails',
			    data: e,
			    success: function () {
			        uni.navigateTo({
			        	url: './details'
			        });
			    }
			});
		},
		go_finish(e) {
			uni.showModal({
				title: '您是否已完成盘点?',
				confirmColor: '#bd3c8c',
				success: function(res) {
					if (res.confirm) {
						console.log('用户点击确定');
					} else if (res.cancel) {
						console.log('用户点击取消');
					}
				}
			});
		}
	}
};
</script>

<style lang="less" scoped>
page {
	background: #ffffff;
}
.order {
	.list {
		padding: 20rpx;
		.li {
			position: relative;
			margin: 18rpx 0;
			background: #fff;
			border-radius: 10rpx;
			box-shadow: 5rpx 0px 20rpx #c5c5c5;
			font-size: 28rpx;
			.order {
				border-bottom: 1px solid #e1e1e1;
				line-height: 96rpx;
				padding: 0 20rpx;
			}
			.shop {
				.msg {
					margin-left: 37rpx;
					padding: 34rpx 20rpx;
					line-height: 46rpx;
					.time {
						color: #999999;
					}
				}
			}
			.genre {
				height: 100rpx;
				.msg {
					font-size: 26rpx;
					.audit {
						position: absolute;
						right: 20rpx;
						bottom: 35rpx;
						width: 180rpx;
						height: 64rpx;
						border-radius: 64rpx;
						line-height: 64rpx;
						border: 1px solid #e1e1e1;
						color: #666666;
						text-align: center;
					}
					.audit1 {
						right: 253rpx;
						border: 1px solid #f70225;
						color: #f70225;
					}
				}
			}
		}
		.li:nth-last-child(1) {
			border-bottom: none;
		}
	}
}
</style>
